<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Controller
 * @subpackage Action
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: Page.php 7 2009-11-14 22:42:08Z nkeyes $
 */


/**
 * 
 * @author Nathan Keyes
 *
 */
class Bushido_Controller_Action_Page extends Bushido_Controller_Action
{
	
	/**
	 * 
	 * 
	 * @return void
	 */
	public function indexAction() 
	{
	}

	/**
	 * 
	 * @return void
	 */
	public function viewAction()
	{
		$pageName = $this->_getParam('page');
		
		$pageClassName = ucfirst($this->getRequest()->getModuleName()) . '_Model_Page_' .$pageName;
		/*
		try
		{
		*/
			$page = Bushido_Page::getPage($pageClassName, null, $this->view);
			
		/*
		}
		catch(Exception $e)
		{
			
			$pageClassName = 'Bushido_Page_' .$pageName;
			$page = Bushido_Page::getPage($pageClassName, null, $this->view);
		}
		*/
			
		//$page->setAccess($this->_acl);
		$page->getConfig()->setConfigOptions($this->_getAllParams());
		
		$session = Bushido_App::session();
		
		$this->challegeAccess($session->userInfo, $page->getResourceId());
		
		$this->view->pageData = $page->getRawData();
		try // try to render page specific view
		{
			
			$pageNameParts = split("_", $pageName);
			if(count($pageNameParts)>1)
			{
				$pageFolder = $pageNameParts[0];
				$pageName = $pageNameParts[1];
			}
			else
			{
				$pageFolder = '';
				$pageName = $pageNameParts[0];
			}
			$this->renderScript('pages/' . $pageFolder . '/' . $pageName . '.phtml');
		}
		catch(Zend_View_Exception $e) // otherwise render the default page view
		{
			$this->render('view');
		}
	}
}